package com.example.Lezedata.ui.fragment.commonfragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.example.Lezedata.R;
import com.example.Lezedata.dataModel.LotteryInfo;
import com.example.Lezedata.ui.fragment.BaseFragment;
import com.example.Lezedata.util.GBInterface;
import com.example.Lezedata.util.GBTimeManager;
import com.example.Lezedata.util.GBUtil;

import java.util.Date;

import bid.Bid;

public class GBLotteryView extends BaseFragment {
    public TextView textView;
    public GBInterface viewCreatedListener;
    public Bid.BidRecordItem bidRecordItem;
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.lottery_view, container, false);
    }

    @Override
    public void initView() {
        super.initView();
        textView = findViewById(R.id.lottery_text);
        if (viewCreatedListener != null){
            viewCreatedListener.onViewCreated(contentView);
        }
    }

    public void setBidRecordItem(Bid.BidRecordItem bidRecordItem) {
        this.bidRecordItem = bidRecordItem;
        String str0 = "Winner: " + GBUtil.mobileReplaceToXxx(bidRecordItem.getPhone());
        String str1 = String.format("Bought:%s bids",bidRecordItem.getBidCount());
        String str2 = String.format("Wish Code: %s",bidRecordItem.getBidCodeList(0));
        Date date = new Date(bidRecordItem.getCreateTime());
        String str3 = String.format("Raffled: %s", GBTimeManager.getInstance().format(date,"yyyy-MM-dd HH:mm:ss"));
        String str4 = String.format("%s\n%s\n%s\n%s",str0,str1,str2,str3);
        textView.setText(str4);
    }

    public void setModel(LotteryInfo model){
        String str0 = "Winner: " + GBUtil.mobileReplaceToXxx(model.mobile);
        String str1 = String.format("Bought:%d bids",model.allBidNid);
        String str2 = String.format("Wish Code: %s",model.code);
        Date date = new Date(model.lotteryTime);
        String str3 = String.format("Raffled: %s", GBTimeManager.getInstance().format(date,"yyyy-MM-dd HH:mm:ss"));
        String str4 = String.format("%s\n%s\n%s\n%s",str0,str1,str2,str3);
        textView.setText(str4);
    }
}
